﻿using System.Globalization;
using System.Windows.Controls;

namespace LFSRecord2.View.Validators
{
    class ProjectFpsValidationRule : ValidationRule
    {
        public int MinFps { get; set; }
        public int MaxFps { get; set; }

        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            byte fps;

            // Is port a whole number?
            if (!byte.TryParse((string)value, out fps))
            {
                return new ValidationResult(false, "Not a number.");
            }

            // Is in range?
            if ((fps < MinFps) || (fps > MaxFps))
            {
                string msg = string.Format(CultureInfo.InvariantCulture, "Project FPS must be between {0} and {1}.", MinFps, MaxFps);
                return new ValidationResult(false, msg);
            }

            // Valid port
            return new ValidationResult(true, null);
        }
    }
}
